package com.itheima.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.itheima.domain.db.Log;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface LogMapper extends BaseMapper<Log> {

    //根据操作类型和操作日期统计人数
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log WHERE TYPE = #{type} AND log_time = #{logTime}")
    Integer countByTypeAndTime(@Param("type") String type, @Param("logTime") String logTime);

    //根据操作日期统计人数
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log WHERE log_time = #{logTime}")
    Integer countByTime(@Param("logTime") String logTime);

    //次日留存
    @Select("SELECT COUNT(DISTINCT user_id) FROM tb_log WHERE log_time = #{today} AND user_id IN\n" +
            "\t(SELECT user_id FROM tb_log WHERE TYPE = '0102' AND log_time = #{yesterday})")
    Integer keep(@Param("yesterday") String yesterday, @Param("today") String today);
}